<?php defined('InNcPHP') or exit('Access Invalid!');?>

<div class="page">
  <div class="fixed-bar">
    <div class="item-title">
      <h3><?php echo $lang['ticket_cate_index_class'];?></h3>
      <ul class="tab-base">
        <li><a href="index.php?act=ticket_category&op=index"><span><?php echo $lang['nc_manage'];?></span></a></li>
        <!-- <li><a href="index.php?act=ticket_category&op=add"><span><?php echo $lang['nc_new'];?></span></a></li> -->
        <li><a href="JavaScript:void(0);" class="current"><span><?php echo $lang['nc_edit'];?></span></a></li>
      </ul>
    </div>
  </div>
  <div class="fixed-empty"></div>
  <form id="goods_class_form" name="goodsClassForm" enctype="multipart/form-data" method="post">
    <input type="hidden" name="form_submit" value="ok" />
    <input type="hidden" name="tc_id" id="tc_id" value="<?php echo $output['cate']['tc_id'];?>" />
    <input type="hidden" name="gc_parent_id" id="gc_parent_id" value="<?php echo $output['cate']['tc_pid'];?>" />
    <table class="table tb-type2">
      <tbody>
        <tr class="noborder">
          <td colspan="2" class="required"><label class="gc_name validation" for="gc_name"><?php echo $lang['ticket_cate_index_name'];?>:</label></td>
        </tr>

        <tr class="noborder">
          <td class="vatop rowform"><input type="text" maxlength="20" <?php echo $output['cate']['tc_pid']==0?"disabled='disabled'":''?> value="<?php echo $output['cate']['tc_name'];?>" name="tc_name" id="gc_name" class="txt"></td>
          <td class="vatop tips"></td>
        </tr>

        <tr class="noborder">
            <td colspan="2" class="required"><label class="validation""><?php echo $lang['ticket_cate_index_subname'];?>:</label></td>
        </tr>
        <tr class="noborder">
            <td class="vatop rowform"><input type="text" maxlength="20" value="<?php echo $output['cate']['tc_subname'];?>" name="tc_subname" class="txt"></td>
            <td class="vatop tips"></td>
        </tr>

        <tr>
          <td colspan="2"><label for="pic"><?php echo '分类图片';?>:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform"><span class="type-file-show"><img class="show_image" src="<?php echo ADMIN_TEMPLATES_URL;?>/images/preview.png">
            <div class="type-file-preview"><img src="<?php echo $output['cate']['tc_icon'];?>" style="width: 100px;height: 100px;"></div>
            </span><span class="type-file-box"><input type='text' name='textfield' id='textfield1' class='type-file-text' />
                <input type='button' name='button' id='button1' value='' class='type-file-button' />
            <input name="pic" type="file" class="type-file-file" id="pic" size="30" hidefocus="true" nc_type="change_pic">
            </span></td>
          <td class="vatop tips"><?php echo '建议用300px * 210px';?></td>
        </tr>
        <tr>
          <td colspan="2" class="required"><label for="gc_sort"><?php echo $lang['nc_sort'];?>:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform"><input type="text" value="<?php echo $output['cate']['tc_sort'] == ''?0:$output['cate']['tc_sort'];?>" name="tc_sort" id="gc_sort" class="txt"></td>
          <td class="vatop tips"><?php echo $lang['ticket_cate_add_update_sort'];?></td>
        </tr>
      </tbody>
      <tfoot>
        <tr class="tfoot"><td colspan="15" ><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span><?php echo $lang['nc_submit'];?></span></a></td>
        </tr>
      </tfoot>
    </table>
  </form>
</div>
<script>
$(document).ready(function(){
	//按钮先执行验证再提交表单
	$("#submitBtn").click(function(){
	    $("#goods_class_form").valid() && $("#goods_class_form").submit();
	});
    //选择文件
	$("#pic").change(function(){
		$("#textfield1").val($(this).val());
	});

    $('#goods_class_form').validate({
        errorPlacement: function(error, element){
            error.appendTo(element.parent().parent().prev().find('td:first'));
        },
        rules : {
            tc_name: {
                required: true,
                remote: {
                    url: 'index.php?act=ticket_category&op=check&type=tc_name_update',
                    type: 'get',
                    data: {
                        tc_name: function(){
                            return $('#gc_name').val();
                        },
                        tc_pid: function() {
                            return $('#gc_parent_id').val();
                        },
                        tc_id: function () {
                            return $('#tc_id').val();
                        }
                    }
                }
            },
            tc_subname: 'required',
            tc_sort: {
                digits: true,
                range: [0, 255]
            }
        },
        messages : {
            tc_name : {
                required: '<?php echo $lang['ticket_cate_add_name_null'];?>',
                remote: '<?php echo $lang['ticket_cate_add_name_exists'];?>'
            },
            tc_subname: '<?php echo $lang['ticket_cate_add_subname_null']; ?>',
            tc_sort: {
                digits: '<?php echo $lang['ticket_cate_add_sort_int'];?>',
                range: '<?php echo $lang['ticket_cate_add_sort_range'];?>'
            }
        }
    });
});
</script>